package VN.EDU.IMIC.DEVELOPER.LETRONGKHANH.SWINGDEMO;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.ImageIcon;

import VN.EDU.IMIC.DEVELOPER.LETRONGKHANH.SWINGDEMO.Controller.LoginController;

import com.sqlserver.imic.edu.vn.ConnectionManager.SqlConnection;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;

public class Demo extends JFrame {

	private JPanel contentPane;
	private JTextField txtTaiKhoan;
	private JTextField txtMatKhau;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Demo frame = new Demo();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Demo() {
		setTitle("DANG NHAP HE THONG");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new TitledBorder(null, "Dang nhap",
				TitledBorder.LEADING, TitledBorder.TOP, null, null));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JLabel lblNewLabel = new JLabel("Tai Khoan");
		lblNewLabel.setHorizontalAlignment(SwingConstants.LEFT);
		lblNewLabel.setBounds(28, 37, 75, 23);
		contentPane.add(lblNewLabel);

		txtTaiKhoan = new JTextField();
		txtTaiKhoan.setBounds(116, 38, 201, 20);
		contentPane.add(txtTaiKhoan);
		txtTaiKhoan.setColumns(10);

		JLabel lblNewLabel_1 = new JLabel("Mat Khau");
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.LEFT);
		lblNewLabel_1.setBounds(28, 71, 75, 23);
		contentPane.add(lblNewLabel_1);

		txtMatKhau = new JTextField();
		txtMatKhau.setBounds(116, 72, 201, 20);
		contentPane.add(txtMatKhau);
		txtMatKhau.setColumns(10);

		JButton btnNewButton = new JButton("Dang nhap");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Connection objConnection;
				SqlConnection obj = new SqlConnection();

				try {
					objConnection = obj.OpenConnection("DESKTOP-F43Q9GJ", "sa",
							"12345", "QLSV", 1433);
					if (!objConnection.isClosed()) {
						LoginController objController = new LoginController(
								objConnection);
						User objUser = new User();
						objUser.setUser(txtTaiKhoan.getText());
						objUser.setPassWord(txtMatKhau.getText());
						if (objController.CheckUser(objUser)) {
							JOptionPane.showMessageDialog(getParent(),
									"Dang nhap thanh cong");

						} else {
							JOptionPane.showMessageDialog(getParent(),
									"Dang nhap that bai");
						}
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
		btnNewButton.setIcon(new ImageIcon(Demo.class
				.getResource("/javax/swing/plaf/metal/icons/ocean/file.gif")));
		btnNewButton.setBounds(66, 135, 131, 23);
		contentPane.add(btnNewButton);

		JButton btnNewButton_1 = new JButton("Thoat");
		btnNewButton_1
				.setIcon(new ImageIcon(
						Demo.class
								.getResource("/javax/swing/plaf/metal/icons/ocean/paletteClose-pressed.gif")));
		btnNewButton_1.setBounds(228, 135, 89, 23);
		contentPane.add(btnNewButton_1);
	}
}
